package cn.xi.controller;


import cn.xi.dao.StudentDao;
import cn.xi.domain.GeneralResult;
import cn.xi.domain.Student;
import cn.xi.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@Transactional
public class ControllerHello implements ControllerHe {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/save")
    @ResponseBody
    public GeneralResult save(@RequestBody Student student) {
        GeneralResult generalResult = new GeneralResult();
        studentService.save(student);
        generalResult.setFlag(true);
        generalResult.setMsg("操作成功");
        return generalResult;

    }

    @RequestMapping("/findbyid")
    @ResponseBody
    public Student findbyid(String name) {
        return studentService.findById(name);
    }


    @RequestMapping("update")
    @ResponseBody
    public GeneralResult update(@RequestBody Student student) {
        GeneralResult generalResult = new GeneralResult();
        studentService.update(student);
        generalResult.setFlag(true);
        generalResult.setMsg("操作成功");
        return generalResult;

    }


    @RequestMapping("delete")
    @ResponseBody
    public GeneralResult delete(String name) {
        GeneralResult generalResult = new GeneralResult();
        studentService.delete(name);
        generalResult.setFlag(true);
        generalResult.setMsg("操作成功");
        return generalResult;

    }

    @RequestMapping("/findpage")
    @ResponseBody
    public PageInfo findpage(Integer page, Integer size) {
        return studentService.findpage(page, size);
    }

}
